<template>
  <view class="order-detail-page">
    <!-- 物流状态区域 -->
    <view class="logistics-status" @click="viewLogistics">
      <view class="status-header">
        <view class="status-text">
          <text class="status">{{ getLogisticsStatusText(orderData.wlStatus) }}</text>
          <text class="estimate" >{{orderData.wlInfo || '暂无物流信息'}}</text>
        </view>
        <image
          src="https://jyoungy.oss-cn-beijing.aliyuncs.com/jyy-mini-sale/order/arrow.png"
          mode="widthFix"
          class="arrow"
        ></image>
      </view>
    </view>

    <!-- 收货地址区域 -->
    <view class="address-section">
      <view class="location-icon">
        <image
          src="https://jyoungy.oss-cn-beijing.aliyuncs.com/jyy-mini-sale/order/address.png"
          mode="widthFix"
        ></image>
      </view>
      <view class="address-content">
        <view class="address-detail">{{ orderData.address }}</view>
        <view class="recipient-info"
          >{{ orderData?.name }} {{ orderData?.phone }}</view
        >
      </view>
    </view>

    <!-- 商品信息区域 -->
    <view class="product-section">
      <view class="product-item" v-for="item in orderData.orderDetailVos" :key="item.goodsId">
        <view class="product-image">
          <image :src="item.listImg" mode="aspectFit"></image>
        </view>
        <view class="product-info">
          <view class="product-name">{{ item.goodsName }}</view>
          <view class="product-quantity"
            >共{{ item.quantity }}件</view
          >
          <view class="product-price">{{ item.price }}</view>
        </view>
      </view>
      <!-- 操作按钮区域 -->
      <view class="action-buttons">
        <button class="btn btn-primary" @click="buyAgain">再来一单</button>
      </view>
    </view>

    <!-- 订单详情区域 -->
    <view class="order-details">
      <view class="detail-row">
        <text class="label">商品总价</text>
        <text class="value priceValue" >{{ orderData.payablePrice }}</text>
      </view>
      <view class="detail-row">
        <text class="label">订单编号</text>
        <view class="value-with-copy">
          <text class="value">{{ orderData.id }}</text>
          <text class="copy-btn" @click="copyOrderNumber">复制</text>
        </view>
      </view>
      <view class="detail-row">
        <text class="label">支付方式</text>
        <text class="value">{{ orderData.payType === 'wx' ? '微信支付' : '账户支付' }}</text>
      </view>
      <view class="detail-row">
        <text class="label">下单时间</text>
        <text class="value">{{ orderData.createTime }}</text>
      </view>
      <view class="detail-row">
        <text class="label">支付时间</text>
        <text class="value">{{ orderData.payTime }}</text>
      </view>
      <view class="detail-row">
        <text class="label">配送方式</text>
        <text class="value">快递配送</text>
      </view>
      <view class="detail-row" style="margin-top: 70rpx;">
        <text class="label">实付款</text>
        <text class="total">合计 <text class="priceValue">{{ orderData.payablePrice }}</text></text>
      </view>
    </view>

    <!-- 底部操作区域 -->
    <view class="bottom-actions">
      <button class="contact-service" @click="contactService">
        <image
          src="https://jyoungy.oss-cn-beijing.aliyuncs.com/jyy-mini-sale/order/service.png"
          mode="widthFix"
        ></image>
        <text>联系客服</text>
      </button>
      <button class="buy-again-btn" @click="buyAgain">再来一单</button>
    </view>
    <ContactServiceModal ref="contactServiceModal" style="z-index: 9999; position: relative;" />

  </view>
</template>

<script>
import orderApi from "@/request/order";
import ContactServiceModal from '@/components/ContactServiceModal.vue'
export default {
  components: {
    ContactServiceModal
  },
  data() {
    return {
      orderId: "",
      orderData: {},
    };
  },
  onLoad(options) {
    this.orderId = options.orderId;
    this.getOrderDetail();
  },
  methods: {
    viewLogistics() {
      uni.navigateTo({
        url: `/pages/order/logistics?orderId=${this.orderId}`,
      });
    },
    // 物流状态 -1-暂无物流信息 0在途，1揽收，2疑难，3签收，4退签，5派件，14拒签。待收货返回，其他状态时返回null.
    getLogisticsStatusText(status) {
      switch (status) {
        case '-1':
          return "暂无物流信息";
        case '0':
          return "运输中";
        case '1':
          return "已揽收";
        case '3':
          return "已签收";
        case '4':
          return "退签";
        case '5':
          return "派件中";
        case '14':
          return "拒签";
        default:
          return '';
      }
    },
    // 获取订单详情
    getOrderDetail() {
      orderApi
        .getOrderDetail({
          orderId: this.orderId,
        })
        .then((res) => {
          this.orderData = res;
        });
    },
    buyAgain() {
      uni.switchTab({
        url: "/pages/mall/index",
      });
    },
    copyOrderNumber() {
      uni.setClipboardData({
        data: this.orderData.id,
        success: () => {
          uni.showToast({
            title: "订单编号已复制",
            icon: "success",
          });
        },
      });
    },
    contactService() {
      this.$refs.contactServiceModal.show();
    },
  },
};
</script>

<style lang="scss" scoped>
.order-detail-page {
  background-color: #fff;
  min-height: 100vh;
  padding-bottom: 150rpx;
}

.logistics-status {
  background-color: #ffffff;
  padding: 40rpx 50rpx;
  padding-bottom: 0;
  border-radius: 0;
}

.status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-icon {
  width: 32rpx;
  height: 32rpx;
  margin-right: 20rpx;

  image {
    width: 100%;
  }
}

.status-text {
  flex: 1;
  display: flex;
  align-items: center;

  text-overflow: ellipsis;
    overflow: hidden;
  .status {
    font-size: 32rpx;
    font-weight: 600;
    color: #000;
    width: fit-content;
    white-space: nowrap;
    margin-right: 20rpx;
  }

  .estimate {
    font-size: 24rpx;
    color: #000;
    white-space: nowrap;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.arrow {
  width: 16rpx;
  height: 16rpx;
  transform: rotate(-90deg);
  opacity: 0.6;
}

.address-section {
  background-color: #ffffff;
  padding: 40rpx 0;
  margin: 0 50rpx;
  margin-bottom: 20rpx;
  display: flex;
  align-items: flex-start;
  border-bottom: 1rpx solid #cbcbcb;
}

.location-icon {
  width: 24rpx;
  height: 24rpx;
  margin-right: 20rpx;
  margin-top: 8rpx;

  image {
    width: 100%;
  }
}

.address-content {
  flex: 1;

  .address-detail {
    font-size: 30rpx;
    color: #333333;
    margin-bottom: 15rpx;
    line-height: 1.5;
    font-weight: 400;
  }

  .recipient-info {
    font-size: 26rpx;
    color: #999999;
    font-weight: 400;
  }
}

.product-section {
  background-color: #ffffff;
  margin: 0 50rpx;
  margin-bottom: 20rpx;
  border-bottom: 1rpx solid #cbcbcb;
}

.product-item {
  display: flex;
  align-items: flex-start;
}

.product-image {
  width: 150rpx;
  height: 150rpx;
  overflow: hidden;
  margin-right: 24rpx;

  image {
    width: 100%;
    height: 100%;
  }
}

.product-info {
  flex: 1;

  .product-name {
    font-size: 30rpx;
    font-weight: 500;
    color: #333333;
    margin-bottom: 12rpx;
    line-height: 1.4;
  }

  .product-quantity {
    font-size: 26rpx;
    color: #999999;
    margin-bottom: 20rpx;
    font-weight: 400;
  }

  .product-price {
    font-size: 32rpx;
    color: #000;
    text-align: right;
    &::before {
      content: "￥";
      font-size: 20rpx;
      color: #000;
    }
  }
}

.action-buttons {
  display: flex;
  justify-content: flex-end;
  margin-top: 60rpx;
  margin-bottom: 50rpx;
  .btn {
    height: 66rpx;
    line-height: 66rpx;
    width: fit-content;
    font-size: 30rpx;
    border: none;
    padding: 0 30rpx;
    border-radius: none;
    background-color: #fff;
    color: #000;
	margin: 0;
  }
}

.order-details {
  background-color: #ffffff;
  margin: 0 50rpx;
  margin-bottom: 20rpx;
  padding-top: 40rpx;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 36rpx;

  &:last-child {
    margin-bottom: 0;
  }

  .label {
    font-size: 30rpx;
    color: #666;
    font-weight: 400;
  }

  .value {
    font-size: 30rpx;
    color: #000;
    font-weight: 400;
  }

  .priceValue {
    font-size: 32rpx;
    &::before {
      content: "￥";
      font-size: 20rpx;
      color: #000;
    }
  }
  .total {
    font-size: 32rpx;
    font-weight: 600;
    color: #333333;
  }
}

.value-with-copy {
  display: flex;
  align-items: center;
  gap: 20rpx;

  .copy-btn {
    font-size: 23rpx;
    color: #333;
    font-weight: 400;
    padding-left: 10rpx;
    border-left: 1rpx solid #999;
  }
}

.payment-total {
  background-color: #ffffff;
  padding: 50rpx 30rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;

  .label {
    font-size: 30rpx;
    color: #333333;
    font-weight: 400;
  }

}

.bottom-actions {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #ffffff;
  padding: 24rpx 30rpx;
  display: flex;
  align-items: center;
  gap: 24rpx;
  border-top: 1rpx solid #e5e5e5;
  z-index: 100;
  justify-content: space-between;
}

.contact-service {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  padding: 0;
  font-size: 24rpx;
  color: #999999;
  box-shadow: none;
  line-height: 1;
  font-weight: 400;
  margin: 0;

  &::after {
    border: none;
    
  }

  image {
    width: 44rpx;
    height: 44rpx;
    margin-bottom: 8rpx;
  }
}

.buy-again-btn {
  padding: 0 30rpx;
  height: 66rpx;
  background-color: #000000;
  color: #ffffff;
  border-radius: 0;
  font-size: 30rpx;
  border: none;
  font-weight: 400;
  line-height: 66rpx;
  margin: 0;
}
</style>
